{% extends "base.html" %}

{% block title %}用户管理 - 管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <h2 class="mb-4">用户管理</h2>
        <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>用户名</th>
                                <th>角色</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for user in users %}
                            <tr>
                                <td>{{ user.id }}</td>
                                <td>{{ user.username }}</td>
                                <td>
                                    {% for role in user.roles %}
                                        {{ role.name }}{% if not loop.last %}, {% endif %}
                                    {% endfor %}
                                </td>
                                <td>
                                    {% if user.is_active %}
                                        <span class="badge bg-success">活跃</span>
                                    {% else %}
                                        <span class="badge bg-danger">禁用</span>
                                    {% endif %}
                                </td>
                                <td>
                                    <div class="btn-group">
                                        <a href="{{ url_for('admin.edit_user', user_id=user.id) }}" class="btn btn-sm btn-primary">编辑</a>
                                        {% if user.is_active %}
                                            <a href="{{ url_for('admin.deactivate_user', user_id=user.id) }}" class="btn btn-sm btn-warning">禁用</a>
                                        {% else %}
                                            <a href="{{ url_for('admin.activate_user', user_id=user.id) }}" class="btn btn-sm btn-success">启用</a>
                                        {% endif %}
                                        <a href="{{ url_for('admin.delete_user', user_id=user.id) }}" class="btn btn-sm btn-danger" onclick="return confirm('确定要删除该用户吗？')">删除</a>
                                    </div>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="mt-3">
                    <a href="{{ url_for('admin.add_user') }}" class="btn btn-primary">添加用户</a>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 